<?php

namespace App\Http\Requests\System;

use App\Http\Requests\BaseRequest;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class Post extends BaseRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'name' => [
                'required',
                Rule::unique('posts')
                    ->ignore(request()->id)
                    ->where(function ($query){
                        $query->whereNull('deleted_at');
                    }),
            ],
            // 'is_leader' => 'required',
            'department_id' => 'required',
            'description' => 'required'
        ];
    }

    public function messages(){
        return [
            'name.required' => '请输入岗位名称',
            'name.unique' => '岗位名称重复',
            // 'is_leader.required' => '请输入是否为领导人',
            'department_id.required' => '请输入部门',
            'description.required' => '请输入岗位描述'
        ];
    }
}
